/**
 * 查看订单控制器
 */
import $_fn from '~plugins'

export default ['$scope','$rootScope','$location','$ui','http','uibDateParser','$timeout','$state',function($scope,$rootScope,$location,$ui,http,uibDateParser,$timeout,$state) {
    // 传过来的 贷款方式    //借款类型(1.车贷 2房贷 3信贷)
    if(false)
    {$scope.searchData = $location.search()
    console.log('查看订单参数',$scope.params)
    // $scope.loanState = $location.search().state 
    console.log('localtion', $location.search(),$location)
    $scope.attaArr = [] //数据列表数组
    $scope.option = {}  //下拉框每个下拉显示数据
    $scope.uploads = {} //上传信息存储
    $scope.apply = {'loanMess':true}
    $scope.state = 1    //选择的贷款方式
    $scope.err = {}  //错误边框是否提示
    $scope.errTip = {}  //错误边框是否提示
    //初始化-方便查看
    $scope.data = {
        /* 借款信息 */
        fee: {},
        order: {},
        /* 基本信息 */
        person: [{id:null, real_name: '', id_card: '', birthdate: '', phone: '', sex: ''}],
        /* 公司信息 */
        company: {},
        /* 车辆信息 */
        car: {},
        /* 房产信息 */
        housing: {},
        propertyPersonal: [{real_name: null, ratio: null}],
        /* 联系人信息 */
        linkMan: {},
        /* 其他联系人信息 */
        json1: {},
        json2: {},
        json3: {},
        /* 附件资料 */
        orderAttachmentList: {}
    }
    $scope.data.personOne = {}

    //获取多种下拉选项类型列表
    http.post('selectOrderInit.do', {}, function (data) {
        console.log('ryy-selectOrderInit', data)
        //贷款方式（订单类型）
        data.data.loanTypeList.unshift({id:'', lt_name:'未填写'})
        $scope.data.order.lt_id = ''
        $scope.option.loanType = data.data.loanTypeList
        //订单来源
        data.data.orderSourceList.unshift({id:'', os_name:'未填写'})
        $scope.data.order.os_id = ''
        $scope.option.orderSource = data.data.orderSourceList
        //资料清单
        data.data.attatchmentTypeList.unshift({id:'', type_name:'未填写'})
        $scope.uploads.attach_id = ''
        $scope.option.dataList = data.data.attatchmentTypeList
        //申请期限
        data.data.applyTermList.unshift({id:'', at_name:'未填写'})
        $scope.data.order.at_id = ''
        $scope.option.period = data.data.applyTermList
        //教育程度
        data.data.educationLevelList.unshift({id:'', education:'未填写'})
        $scope.data.personOne.education = ''
        $scope.option.education = data.data.educationLevelList
        //职位身份
        data.data.positionList.unshift({id:'', position_name:'未填写'})
        $scope.data.personOne.position = ''
        $scope.option.positionList = data.data.positionList
        //还款方式
        $scope.data.order.repayment_way = ''
        $scope.option.replyType = [{name:'未填写',id:''},{name:'先息后本',id:'1'},{name:'等额等息',id:'2'}]
        //选择性别
        $scope.option.sexArr = [{name:'未填写',id:''},{name:'男',id:'1'},{name:'女',id:'2'}]
        //婚姻状况
        $scope.data.personOne.marry = ''
        $scope.option.marital = [{name:'未填写',id:''},{name:'已婚',id:'1'},{name:'未婚',id:'2'},{name:'未知',id:'3'}]
        //微粒贷状况
        $scope.data.personOne.isqqloan = ''
        $scope.option.qqloan = [{name:'未填写',id:''},{name:'有',id:'1'},{name:'无',id:'2'}]

        if(data.errcode == 1){
          // 订单信息
          if($scope.searchData.oid && $scope.searchData.pid){
              http.post('selectOrderInfo.do', {oid:$scope.searchData.oid, pid:$scope.searchData.pid}, function (data) {
                  console.log(data)
                  if(data.errcode ==1){}
                  $scope.$apply(function(){
                      $scope.data = data.data
                      $scope.data.personOne = data.data.person[0]
                      $scope.loanState = $scope.data.order.loan_type
                      //户口地址 省市区
                      let personOne = data.data.person[0]
                      if(personOne.resid_province){
                          $scope.cityid1 = personOne.resid_province +','+ personOne.resid_city +','+ personOne.resid_area
                      }  
                      //现住地址 省市区
                      if(personOne.addr_province){
                          $scope.cityid2 = personOne.addr_province +','+ personOne.addr_city +','+ personOne.addr_area
                      }
                      //公司地址 省市区
                      let company = data.data.company
                      if(company.addr_province){
                          $scope.cityid3 = company.addr_province +','+ company.addr_city +','+ company.addr_area
                      }
                      //房产地址 省市区 
                      let housing = data.data.housing
                      if(housing.addr_province){
                          $scope.cityid4 = housing.addr_province +','+ housing.addr_city +','+ housing.addr_area
                      }
                      //联系人家庭地址 省市区 
                      let linkMan = data.data.linkMan
                      if(linkMan.addr_province){
                          $scope.cityid5 = linkMan.addr_province +','+ linkMan.addr_city +','+ linkMan.addr_area
                      }
                      //房产权利人
                      if(data.data.propertyPersonal && data.data.propertyPersonal.length<1){
                          $scope.data.propertyPersonal = [{real_name: null, ratio: null}]
                      }
                      //图片资料
                      if(data.data.orderAttachmentList && data.data.orderAttachmentList.length>0){
                          $scope.attaArr = data.data.orderAttachmentList
                      }

                      data.data.otherLinkMan[0] && ($scope.data.json1 = data.data.otherLinkMan[0])
                      data.data.otherLinkMan[1] && ($scope.data.json2 = data.data.otherLinkMan[1])
                      data.data.otherLinkMan[2] && ($scope.data.json3 = data.data.otherLinkMan[2])
                      console.log('edit-init', $scope.data,$scope)

                      $scope.showCar = 0
                      $scope.showCompany = 0
                      $scope.showHousing = 0
                      $scope.showlinkMan = 0
                      for(let i in $scope.data.car){
                        if($scope.data.car[i] && $scope.data.car[i] !='-1'){
                          $scope.showCar++
                        }
                      }
                      for(let i in $scope.data.company){
                        if($scope.data.company[i]){
                          $scope.showCompany++
                        }
                      }
                      for(let i in $scope.data.housing){
                        if($scope.data.housing[i] && $scope.data.housing[i] !='-1'){
                          $scope.showHousing++
                        }
                      }
                      for(let i in $scope.data.linkMan){
                        if($scope.data.linkMan[i]){
                          $scope.showlinkMan++
                        }
                      }
                  })
              })
          }
        }

    })

    $scope.backBefore = function(){
      window.history.back();
    }
    // console.log('ryy-addrtext:', $('.get-textAddr input').addAttr('readonly'))

    /**
     * tab菜单切换
     */
    $scope.show = function (params, ele) {
        //当params为借款人 借款人信息
        if (params == 'loanMess' || params == 'dataList') {
            $_fn.applyShow(params,$scope.apply)
            //切换菜单
            // $('.public-PoBefore-nav li a').removeClass('active').removeClass('activePublic')
            // $(ele.target).addClass('active')
        }
    }

    //图片预加载
    $scope.loadImage = $_fn.loadImage;
    //图片查看
    $scope.imgList = $_fn.imgList;}

}]
